package com.aglhz.base;

import com.aglhz.nature.R;

import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;


public class BaseActivity extends ActionBarActivity{
	private ViewGroup actionBarCustomView;
	private ImageButton leftItem;
	private Button rightItem;
	//private TextView textViewTitle;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setCustomActionView(R.layout.custom_actionbar);
	}
	
	private void setCustomActionView(int layoutId){
		ActionBar.LayoutParams lp=new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT,ActionBar.LayoutParams.MATCH_PARENT,Gravity.CENTER);
		actionBarCustomView=(ViewGroup)getLayoutInflater().inflate(layoutId, null);
		ActionBar actionBar = getSupportActionBar(); 
		
		getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

		actionBar.setCustomView(actionBarCustomView, lp);
		leftItem = (ImageButton) actionBarCustomView.findViewById(R.id.left_item);
		rightItem =(Button)actionBarCustomView.findViewById(R.id.right_item);
		leftItem.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// 返回
				onBackPressed();
			}
		});
	}
	protected void setActionBarTitle(String title){
		TextView textView = (TextView) actionBarCustomView.findViewById(R.id.textView_actionbarTitle);
		textView.setText(title);
	}
	//隐藏左边返回图标
	protected void goneActionBarLeft(){
		leftItem.setVisibility(View.GONE);
	}
	
	
	//显示右边按钮
	protected void showRightItem(String text,OnClickListener l){
		rightItem.setVisibility(View.VISIBLE);
		rightItem.setText(text);
		rightItem.setOnClickListener(l);
	}
	
}
